/// 上传统计信息模型
///
/// 表示按状态分类的图片统计信息
class UploadStats {
  /// 全部图片数量
  final int allCount;

  /// 待挑选的图片数量
  final int pendingCount;

  /// 正在上传的图片数量
  final int uploadingCount;

  /// 已上传的图片数量
  final int uploadedCount;

  /// 上传失败的图片数量
  final int failedCount;

  const UploadStats({
    required this.allCount,
    required this.pendingCount,
    required this.uploadingCount,
    required this.uploadedCount,
    required this.failedCount,
  });

  /// 验证数据约束：全部 = 待挑 + 上传中 + 已上传 + 失败
  bool isValid() {
    return allCount ==
        (pendingCount + uploadingCount + uploadedCount + failedCount);
  }

  /// 创建副本
  UploadStats copyWith({
    int? allCount,
    int? pendingCount,
    int? uploadingCount,
    int? uploadedCount,
    int? failedCount,
  }) {
    return UploadStats(
      allCount: allCount ?? this.allCount,
      pendingCount: pendingCount ?? this.pendingCount,
      uploadingCount: uploadingCount ?? this.uploadingCount,
      uploadedCount: uploadedCount ?? this.uploadedCount,
      failedCount: failedCount ?? this.failedCount,
    );
  }

  @override
  String toString() {
    return 'UploadStats(all: $allCount, pending: $pendingCount, '
        'uploading: $uploadingCount, uploaded: $uploadedCount, failed: $failedCount)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is UploadStats &&
        other.allCount == allCount &&
        other.pendingCount == pendingCount &&
        other.uploadingCount == uploadingCount &&
        other.uploadedCount == uploadedCount &&
        other.failedCount == failedCount;
  }

  @override
  int get hashCode {
    return Object.hash(
      allCount,
      pendingCount,
      uploadingCount,
      uploadedCount,
      failedCount,
    );
  }
}
